﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Grain.Crm.ExcelExtractor.InputDescription;

namespace Grain.Crm.ExcelImporter
{

    public static class ListExtensions
    {
        public static ValueDescription GetByXlsValueName(this IEnumerable<ValueDescription> source, string name)
        {
            foreach (var item in source)
                if (item.XlsDescription == name)
                    return item;

            throw new InvalidOperationException(
                "The collection does not contain a value-description by specified name:" + name);

        }

        public static ValueDescription GetByCrmDisplayName(this IEnumerable<ValueDescription> source, string name)
        {
            foreach (var item in source)
                if (item.CrmDisplayName == name)
                    return item;

            throw new InvalidOperationException(
                "The collection does not contain a Crm display name by specified name:" + name);

        }
    }

}
